"""
内容：放置后台登录的page
作者：7
"""
# 引入模块
from ECshop.common.base import Base,create_browser
# 创建类
class PageLoginAdmin(Base):
    url = 'http://localhost:8080/ecshop/admin'
    close_button = ('css selector','span[onclick="btnCancel(this)"]')
    switch_button =('class name','btn-tab')
    username = ('name','username')
    password=('name','password')
    is_remember = ('name','remember')
    login_button = ('class name','btn-a')
    is_success=('css selector','div[id="foot-div"]>a')
    frame_name = 'menu-frame'
    # 确认网页
    def page_login_admin_open_web(self):
        self.base_open_web(self.url)
    # 点击X按钮
    def page_login_admin_close_button(self):
        self.base_click(self.close_button)
    # 切换到ecshop登录
    def page_login_admin_swith_button(self):
        self.base_click(self.switch_button)
    # 输入账号
    def page_login_admin_input_username(self,your_content):
        self.base_input_content(self.username,your_content)
    # 输入密码
    def page_login_admin_input_password(self,your_content):
        self.base_input_content(self.password,your_content)
    # 勾选自动登录
    def page_login_admin_is_remember(self):
        self.base_click(self.is_remember)
    # 点击登录按钮
    def page_login_admin_login_button(self):
        self.base_click(self.login_button)
    # 进入frame
    def page_login_admin_in_frame(self):
        self.base_in_frame(self.frame_name)
    # 获取文本值
    def page_login_admin_is_success(self):
        return self.base_get_text(self.is_success)
    # 关闭浏览器
    def page_login_admin_quit(self):
        self.base_quit()
if __name__ == '__main__':
    p1=PageLoginAdmin(create_browser())
    p1.page_login_admin_open_web()
    p1.page_login_admin_close_button()
    p1.page_login_admin_swith_button()
    p1.page_login_admin_input_username('root')
    p1.page_login_admin_input_password('root123456')
    p1.page_login_admin_is_remember()
    p1.page_login_admin_login_button()
    p1.page_login_admin_in_frame()
    print(p1.page_login_admin_is_success())
    if p1.page_login_admin_is_success() =='root':
        print('登录成功')
    else:
        print('登录失败')
    p1.page_login_admin_quit()